<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'请假记录'),	
);
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_yiliao_body_out',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['mid']=pdo_getcolumn('jy_yiliao_body',array('id'=>$item['bodyid']),'mid');
			$item['username']=pdo_getcolumn('jy_yiliao_user',array('mid'=>$item['mid']),'nickname');
			$item['name']=pdo_getcolumn('jy_yiliao_body',array('id'=>$item['bodyid']),'name');
			$item['sex']=pdo_getcolumn('jy_yiliao_body',array('id'=>$item['bodyid']),'sex');
			$item['sex']=$item['sex']==0?'女':'男';
			if($item['classid']){
				$item['classtitle']=pdo_getcolumn('jy_yiliao_class',array('id'=>$item['classid']),'title');
				$item['classworkerid']=pdo_getcolumn('jy_yiliao_class',array('id'=>$item['classid']),'workerid');
				$item['classgroup']=pdo_getcolumn('jy_yiliao_class_group',array('id'=>$item['classid']),'title');
				$item['classworker']=pdo_getcolumn('jy_yiliao_worker',array('id'=>$item['classworkerid']),'name');
			}
			if($item['lessonid']){
				$item['lessontitle']=pdo_getcolumn('jy_yiliao_lesson',array('id'=>$item['lessonid']),'title');
				$item['lessonworkerid']=pdo_getcolumn('jy_yiliao_lesson',array('id'=>$item['lessonid']),'workerid');
				$item['lessonworker']=pdo_getcolumn('jy_yiliao_worker',array('id'=>$item['lessonworkerid']),'name');
				$item['classid']=pdo_getcolumn('jy_yiliao_lesson',array('id'=>$item['lessonid']),'classid');
				$item['classtitle']=pdo_getcolumn('jy_yiliao_class',array('id'=>$item['classid']),'title');
				$item['classworkerid']=pdo_getcolumn('jy_yiliao_class',array('id'=>$item['classid']),'workerid');
				$item['classgroup']=pdo_getcolumn('jy_yiliao_class_group',array('id'=>$item['classid']),'title');
				$item['classworker']=pdo_getcolumn('jy_yiliao_worker',array('id'=>$item['classworkerid']),'name');
				$item['lessontimes']=pdo_getcolumn('jy_yiliao_lesson',array('id'=>$item['lessonid']),'times');
			}
			if($item['storeid']){
				$item['storetitle']=pdo_getcolumn('jy_yiliao_store',array('id'=>$item['storeid']),'title');
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('title'=>'学员_username','type'=>'img_string','img'=>'avatar',
			'data'=>array(
				array('title'=>'家长：','name'=>'username'),
				array('title'=>'学员：','name'=>'name','unit'=>'sex')
				)
			),
			array('name'=>'storetitle','title'=>'所属校区','type'=>'string'),
			array('name'=>'classtitle','title'=>'所属班级','type'=>'string'),
			array('name'=>'lessontitle','title'=>'学员科室','type'=>'string'),
		),'action'=>array(
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_yiliao_body_out',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回科室列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('name'=>'title','title'=>'科室名称','type'=>'string'),
					array('name'=>'classid','title'=>'所属班级','type'=>'select','options'=>'class'),
					array('name'=>'logo','title'=>'logo','type'=>'image','help'=>'建议尺寸：640宽*220高'),
					array('name'=>'image','title'=>'展示图片','type'=>'image','help'=>'建议尺寸：640宽*220高'),
					array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'type'),
					array('name'=>'istimes','title'=>'按课时?','type'=>'switch'),
					array('name'=>'times','title'=>'整个阶段课时数','type'=>'unitstring','unit'=>'次','show'=>array('istimes'=>1)),
					array('name'=>'price','title'=>'价格','type'=>'unitstring','unit'=>'元'),
					array('name'=>'time','title'=>'上课时间','type'=>'time_hour'),
					array('name'=>'description','title'=>'简要描述','type'=>'text'),
					array('name'=>'content','title'=>'详细介绍','type'=>'richtext'),
				//	array('name'=>'storeid','title'=>'上课人数','type'=>'string'),
				//	array('name'=>'person_limit','title'=>'上课人数','type'=>'string'),
					array('name'=>'paixu','title'=>'排序','type'=>'string'),
					array('name'=>'status','title'=>'状态','type'=>'switch'),
				)
			),
		)
	);
	$return['class']=pdo_getall('jy_yiliao_class',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));
	$return['type']=$this->lesson_type;
	$return['htmls']=$htmls;
	
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['classid']){
		exi('请选择班级','error');
	}
	$postdata['time']=ijson_encode($postdata['time']);	
	$data=array_fields(array('title','logo','classid','image','type','content','description','paixu','status','price','times','istimes'),$postdata);
	$id=intval($postdata['id']);
	
	if($id){
		pdo_update('jy_yiliao_body_out',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_yiliao_body_out',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_yiliao_body_out',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的科室！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_yiliao_body_out',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}